package com.longcai.piaojia.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.HomeGet;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.pager.CarouselChild;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

/**
 * Created by Administrator on 2015/6/3.
 */
public class ViewHomeAdvert extends CarouselChild<HomeGet.HomeBannerEntity> {

    private LayoutInflater layoutInflater;
    private boolean is_show = true;

    public ViewHomeAdvert(Context context, AttributeSet attrs) {

        super(context, attrs);

        layoutInflater = LayoutInflater.from(context);

    }

    @Override
    protected boolean isPlay() {
        return true;
    }

    public void setIsShow(boolean is_show){

        this.is_show = is_show;

    }

    @Override
    protected View getView(HomeGet.HomeBannerEntity homeBannerEntity) {

        View view = layoutInflater.inflate(R.layout.fragment_home_advert, null);

        ImageView item_advert_image = (ImageView) view.findViewById(R.id.item_advert_image);
        item_advert_image.setScaleType(ImageView.ScaleType.FIT_XY);

        GlideLoader.getInstance().get(getContext(), homeBannerEntity.picurl, item_advert_image, R.mipmap.banner);

        return view;

    }

    @Override
    protected View indicatorLayout(LinearLayout indicatorLayout) {

        indicatorLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

        indicatorLayout.setPadding(0, 0, 0, 0);

        return indicatorLayout;

    }

    @Override
    protected View indicator(View indicator) {

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        params.leftMargin = params.rightMargin = ScaleScreenHelperFactory.getInstance().getWidthHeight(20);

        params.bottomMargin = ScaleScreenHelperFactory.getInstance().getWidthHeight(63);

        indicator.setLayoutParams(params);

        return ScaleScreenHelperFactory.getInstance().loadViewWidthHeight(indicator, 18, 18);

    }

    @Override
    protected int indicatorOff() {

        if(is_show){

            return R.mipmap.shape_advert_indicator_off;

        }else{

            return 0;

        }

    }

    @Override
    protected int indicatorOn() {

        if(is_show){

            return R.mipmap.shape_advert_indicator_on;

        }else{

            return 0;

        }

    }

}
